package com.touchstone.synchdata.common.result;

import cn.hutool.core.util.StrUtil;
import com.touchstone.synchdata.common.enums.ResultEnum;
import lombok.Data;

/**
 * @Description : 返回结果封装
 * @Author : hunter
 * @Date: 2019-06-28 15:45
 * @Version: 1.0
 **/
@Data
public class ResultVO<T> {

    /**
     * 返回编码
     */
    private Integer code;

    /**
     * 返回信息提示
     */
    private String msg;

    /**
     * 返回数据
     */
    private T data;

    /**
     * 返回记录数目
     */
    private Integer count;


    public ResultVO() {
    }

    public ResultVO(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultVO(Integer code, String msg, Integer count, T data) {
        this.code = code;
        this.msg = msg;
        this.count = count;
        this.data = data;
    }

    public static ResultVO success() {
        return success(ResultEnum.SUCCESS.getDesc());
    }

    public static ResultVO success(String msg) {
        return success(msg, null, null);
    }

    public static <T> ResultVO success(T data) {
        return success(null, data, 0);
    }

    public static <T> ResultVO success(T data, Integer count) {
        return success(null, data, count);
    }

    public static <T> ResultVO success(String msg, T data, Integer count) {
        return new ResultVO(ResultEnum.SUCCESS.getStatusCode(), StrUtil.isEmpty(msg) ? ResultEnum.SUCCESS.getDesc() : msg, count, data);
    }

    public static ResultVO NO_FOUND() {
        return new ResultVO(ResultEnum.NO_FOUND.getStatusCode(), ResultEnum.NO_FOUND.getDesc());
    }

    public static ResultVO noRecord(){
        return noRecord(null);
    }

    public static ResultVO noRecord(String msg) {
        return new ResultVO(ResultEnum.NO_RECORD.getStatusCode(), StrUtil.isEmpty(msg) ? ResultEnum.NO_RECORD.getDesc() : msg);
    }

    public static ResultVO error() {
        return new ResultVO(ResultEnum.ERROR.getStatusCode(), ResultEnum.ERROR.getDesc());
    }

    public static ResultVO error(String msg) {
        return new ResultVO(ResultEnum.ERROR.getStatusCode(), StrUtil.isNotEmpty(msg) ? msg : ResultEnum.ERROR.getDesc());
    }

    public static ResultVO error(String msg, Integer errorCode) {
        return new ResultVO(errorCode, StrUtil.isNotEmpty(msg) ? msg : ResultEnum.ERROR.getDesc());
    }

    public static ResultVO fail(String msg) {
        return new ResultVO(ResultEnum.FAIL.getStatusCode(), StrUtil.isEmpty(msg) ? ResultEnum.FAIL.getDesc() : msg);
    }

    public static <T> ResultVO successResultCountVo(Integer count, T data) {
        return new ResultVO(ResultEnum.SUCCESS.getStatusCode(), ResultEnum.SUCCESS.getDesc(), count, data);
    }

    public static ResultVO noToken() {
        return new ResultVO(ResultEnum.NO_TOKEN.getStatusCode(), ResultEnum.NO_TOKEN.getDesc());
    }

    public static ResultVO refreshToken() {
        return new ResultVO(ResultEnum.TOKEN_REFRESH.getStatusCode(), ResultEnum.TOKEN_REFRESH.getDesc());
    }

    public static ResultVO tokenInvalid() {
        return new ResultVO(ResultEnum.TOKEN_INVALID.getStatusCode(), ResultEnum.TOKEN_INVALID.getDesc());
    }

    public static ResultVO tokenInvalid(String msg) {
        return new ResultVO(ResultEnum.TOKEN_INVALID.getStatusCode(), StrUtil.isEmpty(msg) ? ResultEnum.TOKEN_INVALID.getDesc() : msg);
    }

    public static ResultVO noPermission() {
        return new ResultVO(ResultEnum.NO_PERMISSION.getStatusCode(), ResultEnum.NO_PERMISSION.getDesc());
    }

    public static ResultVO noMatch(){
        return noMatch(null);
    }
    public static ResultVO noMatch(String message) {
        return new ResultVO(ResultEnum.NO_MATCH.getStatusCode(), StrUtil.isEmpty(message) ? ResultEnum.NO_MATCH.getDesc() : message);
    }

    public static ResultVO noLogin(){
        return noLogin(null);
    }
    public static ResultVO noLogin(String message) {
        return new ResultVO(ResultEnum.NO_LOGIN.getStatusCode(), StrUtil.isEmpty(message) ? ResultEnum.NO_LOGIN.getDesc() : message);
    }

    public static ResultVO reLogin() {
        return new ResultVO(ResultEnum.RE_LOGIN.getStatusCode(), ResultEnum.RE_LOGIN.getDesc());
    }

    public static ResultVO reLogin(String message){
        return new ResultVO(ResultEnum.RE_LOGIN.getStatusCode(), StrUtil.isEmpty(message) ? ResultEnum.RE_LOGIN.getDesc() : message);
    }
}
